<!doctype html>
<html>
{include file="head.html"}

<body>
  
 <div class="fullscreen">
  <div class="scroll_content">
    <div class="topfixed">
      <div class="t_left"><a href="/index.php"><i class="back"></i></a></div>
      <div class="t_main">会员登录</div>
      <div class="t_right"><a class="link" href="javascript:window.location.reload();">刷新</a></div>
    </div>
    <div class="paddingheight"></div>
    <div class="loginbox">
      <div class="f_padding">
      <form id="login-form">
      <input type="hidden" name="backurl" id="backurl" value="{$smarty.server.HTTP_REFERER}">
        <ul class="form">
          <li>
            <input name="username" id="username" type="text" placeholder="用户名/手机/邮箱" class="inp">
          </li>
          <li>
            <input name="password" id="password" type="password" placeholder="密码" class="inp">
          </li>
           <li>
          	<label for="autologin">自动登录</label>
          	<input name="autologin" id="autologin" type="checkbox" checked="" value="1" />
          </li>
          <li>
            <button type="button" id="login-submit" class="btn" value="">立即登录</button>
          </li>
          <li >
            <div class="thirdlogin" style="display:none"> 第三方登录：<aa style=" cursor:pointer" onClick="appLogin('weixin')" class="ico weixin"></aa> </div>
          </li>
          
          <li><a href="/index.php?m=register" class="links">还不是会员？立即注册</a></li>
        </ul>
        </form>
      </div>
    </div>
  </div>
</div>
<script type="text/javascript" class="jsa-text">
var auths={};
var postdata={};
function appReady(){
	// 获取登录认证通道
	
	plus.oauth.getServices(function(services){	 
		for(var i in services){
			var service=services[i];			 
			auths[service.id]=service;			 
		}
	},function(e){		 
	});
}
setTimeout(function(){
	if(window.plus){
		$(".thirdlogin").show();
		appReady();
	}
},600);
function appLogin(id){
	logoutAll(); 
	var auth=auths[id];
	if(auth){
		 
		 
		 
		 
		auth.login(function(){
			 
		  
			
			if(id=='weixin'){
				 
				 postdata={
					username:$("#username").val(),
					password:$("#password").val(),
					appname:'getui',
					token:info.token,
					clientid:info.clientid,
					appid:info.appid,
					appkey:info.appkey
				}
				$.get("/index.php?m=wxlogin&a=app&ajax=1&openid="+auth.authResult.openid+"&access_token="+auth.authResult.access_token,postdata,function(data){
					if(data.error){
						 skyToast(data.message);
					}else{
						skyToast("登录成功");
						var wobj = plus.webview.currentWebview();
						wobj.hide("slide-out-right"); 
					}
				},"json");
			}
			 
		},function(e){
		 
			skyToast("登录失败");
		});
	}else{
		 
		skyToast("登录失败");
	}
}

function logoutAll(){
	 
	for(var i in auths){
		logout(auths[i]);
	}
}
function logout(auth){
	auth.logout(function(){
		 
	},function(e){
		 
	});
}
	
$(function(){
	$(document).on("click","#login-submit",function(){	
		if(typeof(plus)!="undefined"){
			var info = plus.push.getClientInfo();
			postdata={
				username:$("#username").val(),
				password:$("#password").val(),
				backurl:$("#backurl").val(),
				appname:'getui',
				token:info.token,
				clientid:info.clientid,
				appid:info.appid,
				appkey:info.appkey
			}
		}else{
			 
			var postdata={
				username:$("#username").val(),
				password:$("#password").val(),
				backurl:$("#backurl").val(),
				autologin:$("#autologin").is(':checked')?1:0
			}
		}
		$.post("/index.php?m=login&a=loginSave&ajax=1",postdata,function(data){
			if(data.error==1){
				skyToast(data.message);
			}else{
				skyToast("登陆成功");
				setTimeout(function(){
					window.location=data.url;
				},700);
			}
		},"json");
	});
});
</script>
</body>
</html>
